<template>
	<div style="width: 100%;">
		<div style="display: flex; width: 100%;">
			<el-link style="width: 8%;" @click="gobreed()"> 返回品种管理</el-link>
			<div style="width: 100%;"><p style="text-align: center;">{{data.a}}</p></div>
		</div>
		<div style="background-color: #E1337F;height: 0.1rem;"></div>
		<el-card >
			<div style="width: 100%;">
				<el-main>
					<h2 style="text-align: center;">{{data.a}}</h2>
					<div style="margin-left: 40rem;">
					<el-form :model="data.breed" :rules="rules" ref="formRef">
						<el-form-item  label="编号:" prop="breedid">
						      <el-input v-model="data.breed.breedid" placeholder="编号" :prefix-icon="Cellphone" style="width: 16rem;" disabled=""/>
						    </el-form-item>
						<el-form-item label="名称:" prop="breedname">
							<el-input v-model="data.breed.breedname" placeholder="名称" :prefix-icon="Cellphone" style="width: 16rem;"></el-input>
						</el-form-item>
						<el-form-item label="顺序:" prop="order">
							<el-input v-model="data.breed.order" placeholder="顺序" :prefix-icon="Cellphone" style="width: 16rem;"></el-input>
						</el-form-item>
						<el-form-item label="数量:" prop="num">
							<el-input v-model="data.breed.num" placeholder="数量" :prefix-icon="Cellphone" style="width: 16rem;"></el-input>
						</el-form-item>
						
					</el-form>
					<el-button  @click="add()" style="background-color: #E1337F;  margin-left: 6rem;color: #FFFFFF;">{{data.a}}</el-button>
					</div>
				</el-main>
			</div>
		</el-card>
		</div>
</template>

<script lang="ts" setup>
	import {ref, reactive,onMounted,computed} from"vue"
		import {$get,$postx,$postj,$postf} from '../../../ajax/index.js'
		import { ElMessage, ElMessageBox } from 'element-plus'
		import router from"../../../router/index.js"
		import store from "../../../store/index.js"
		import {Search,ShoppingCart,Plus,EditPen} from '@element-plus/icons-vue'
		import bottom from "../../../components/bottom.vue"
		import {useRoute} from "vue-router"
		import {success,warning,message,errors} from '../../../store/alert.js'
		const route =useRoute()
	const data=reactive({
			breed:{breedid:0,breedname:"",order:"",num:0},
			a:"添加品种"
		})		
		
		function gobreed(){
			
			router.push("/adm/breed")
			
			
		}
		function add(){
			if(data.breed.breedname==""||data.breed.order==""){
				errors(data.a+"信息不允许为空")
				return
			}
			const fd = new FormData();
			fd.append("breedid",data.breed.breedid)
			fd.append("breedname",data.breed.breedname)
			fd.append("order",data.breed.order)
			fd.append("num",data.breed.num)
			let s="/adm/breed/add"
			if(data.breed.breedid!=0)s="/adm/breed/update"
			$postf(s,fd).then((read)=>{
				success(read.data.msg)
				router.push("/adm/breed")
			})
			
			
		}
		
		
		onMounted(()=>{
		 let s=route.query.id
			if(s!=undefined){
				data.a="更改品种"
				$get("/adm/breed/findById/"+s).then((read)=>{
					
					data.breed=read.data.data
				})
				
				
				
			}
			
			
		})
		
</script>

<style>
</style>
